package logic

import (
	"context"
	"store/storerpc/storerpc"

	"store/storeapi/internal/svc"
	"store/storeapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type StoreAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewStoreAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoreAddLogic {
	return &StoreAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *StoreAddLogic) StoreAdd(req *types.StoreAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	_, err = l.svcCtx.StoreRpc.StoreAdd(l.ctx, &storerpc.StoreAddRequest{
		StoreName:  req.StoreName,
		Nickname:   req.Nickname,
		Address:    req.Address,
		Price:      req.Price,
		Shopkeeper: req.Shopkeeper,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: "门店信息错误",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "门店添加成功",
		Data:    nil,
	}, nil
}
